package org.example.tree;

/**
 * @author liyishan
 * @date 2024/7/16 11:24
 * @apiNote
 */

public class Test00938RangeSumBST {

    public int rangeSumBST(TreeNode root, int low, int high) {
        if(root == null){
            return 0;
        }
        if(root.val < low){
            return rangeSumBST(root.right,low,high);
        }
        if(root.val > high){
            return rangeSumBST(root.left,low,high);
        }
        return root.val + rangeSumBST(root.left, low, high) + rangeSumBST(root.right, low, high);
    }
}
